package com.bootdo.common.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class R<T> extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;

	public R() {
		put("code", 0);
		put("msg", "操作成功");
	}
	
	public R(T domain) {
		put("code", 0);
		put("msg", "操作成功");
		put("domain", domain);
	}

	public static R<?> error() {
		return error(1, "操作失败");
	}

	public static R<?> error(String msg) {
		return error(500, msg);
	}

	public static R<?> error(int code, String msg) {
		R<?> r = new R<Object>();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static R<?> ok(String msg) {
		R<?> r = new R<Object>();
		r.put("msg", msg);
		return r;
	}
	
	public R<T> domain(Map<String, Double> result) {
		this.put("domain", result);
		return this;
	}
	
	public R<T> list(List<?> list) {
		this.put("domain", list);
		return this;
	}

	public static R<?> ok(Map<String, Object> map) {
		R<?> r = new R<Object>();
		r.putAll(map);
		return r;
	}

	public static R<?> ok() {
		return new R<Object>();
	}

	@Override
	public R<T> put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
